
var time = require("../../utils/util.js");
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    typeindex: 0,
    list: [],
    pageNum: 1,
    pageSize: 10,
    widheight: ''
  },
  onChange(event) {
    var that = this;
    console.log(event)
    that.setData({
      typeindex: event.detail.index,
      pageNum: 1,
    })
    wx.request({    
      url: time.httpurl + '/schedule/app/dailyTask/getDailyTask/' + that.data.pageNum + '/' + that.data.pageSize,
      method: 'POST',
      header: {
        'AppType': '1',
        'Authorization': wx.getStorageSync("token"),
      },
      data:{
        "personType": 2,
        "personIdList":[],//人员列表
        "organizationId":null,//组织id
        "taskStatus": event.detail.index,//状态
        "taskStartTime":"",//开始时间
        "taskEndTime":""//结束时间
       },
      success: function (res) {
        console.log(res,'list');
        if(res.data.code == 200){
          that.setData({
            list: res.data.rows
          })
          that.setData({
            total: res.data.total
          })
        }else if(res.data.code == 401 || res.data.code == 403){
          app.login();
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }     
      }
    })
  },
  getdel: function(event){
    console.log(event);
    if(event.currentTarget.dataset.id != undefined){
      wx.navigateTo({
        url: '../details/details?orderid=' + event.currentTarget.dataset.id + '&typename=' + event.currentTarget.dataset.typename,
      })
    }    
  },
  onGoodsScroll: function(e){
    var that = this;
    console.log(e,that.data.pageNum,Math.ceil(that.data.total/that.data.pageSize),that.data.typeindex);
    if(that.data.pageNum < Math.ceil(that.data.total/that.data.pageSize)){
      that.setData({
        pageNum: that.data.pageNum + 1
      })
      wx.request({     
        url: time.httpurl + '/schedule/app/dailyTask/getDailyTask/' + that.data.pageNum + '/' + that.data.pageSize,
        method: 'POST',
        header: {
          'AppType': '1',
          'Authorization': wx.getStorageSync("token"),
        },
        data:{
          "personType": 2,
          "personIdList":[],//人员列表
          "organizationId":null,//组织id
          "taskStatus": that.data.typeindex,//状态
          "taskStartTime":"",//开始时间
          "taskEndTime":""//结束时间
         },
        success: function (res) {
          console.log(res,'list');
          if(res.data.code == 200){
            that.setData({
              list: that.data.list.concat(res.data.rows)
            })
          }else if(res.data.code == 401 || res.data.code == 403){
            app.login();
          }else{
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000
            })
          }     
        }
      })
    }   
  },
  task: function(event){
    console.log(event)
    if(event.currentTarget.dataset.id != undefined){
      wx.navigateTo({
        url: '../dailyhandle/dailyhandle?id=' + event.currentTarget.dataset.id+'&personid=' + event.currentTarget.dataset.personid+'&sendpersonid=' + event.currentTarget.dataset.sendpersonid+'&content=' + event.currentTarget.dataset.content,
      })
    }
  },
  record: function(event){
    if(event.currentTarget.dataset.id != undefined){
      wx.navigateTo({
        url: '../dailyrecord/dailyrecord?id=' + event.currentTarget.dataset.id,
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          widheight: res.screenHeight - 110,
          pageSize: Math.ceil((res.screenHeight - 60)/125)
        });
        wx.request({     
          url: time.httpurl + '/schedule/app/dailyTask/getDailyTask/' + that.data.pageNum + '/' + that.data.pageSize,
          method: 'POST',
          header: {
            'AppType': '1',
            'Authorization': wx.getStorageSync("token"),
          },
          data:{
            "personType": 2,
            "personIdList":[],//人员列表
            "organizationId":null,//组织id
            "taskStatus": that.data.typeindex,//状态
            "taskStartTime":"",//开始时间
            "taskEndTime":""//结束时间
           },
          success: function (res) {
            console.log(res,'list');
            if(res.data.code == 200){
              that.setData({
                list: res.data.rows
              })
              that.setData({
                total: res.data.total
              })
            }else if(res.data.code == 401 || res.data.code == 403){
              app.login();
            }else{
              wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 2000
              })
            }     
          }
        })
      }
    });
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
 
  }
})